include soem.mk
# 定义编译器
# CROSS_COMPILE = aarch64-buildroot-linux-gnu-
CC = gcc
# 定义库的名称
LIB_NAME = libsoem.a
# 应用程序
APP_NAME = app
# 测试程序
TEST_APP = test
# 生成目标文件列表（.o文件）
SOEM_OBJ = $(SOEM_SRC:.c=.o)
USER_OBJ = $(USER_SRC:.c=.o)
# 默认目标：生成静态库
all: $(LIB_NAME) $(APP_NAME) $(TEST_APP)
$(APP_NAME): $(USER_OBJ) $(LIB_NAME) 
	$(CROSS_COMPILE)$(CC) $(USER_CFLAGS) $(CFLAGS) $^ -o $@ -L./ -lsoem -lpthread ## 只取第一个依赖项: $(USER_OBJ) 
# test
EBOX_APP = ebox
EEPROMTOOL_APP = eepromtool
EOE_APP = eoe_test
FIRM_UPDATE_APP = firm_update
RED_APP = red_test
SIMPLE_APP = simple_test
SALVEINFO_APP = slaveinfo
ALIASTOOL_APP = aliastool

$(TEST_APP): $(EBOX_APP) $(EEPROMTOOL_APP) $(EOE_APP) $(FIRM_UPDATE_APP) $(RED_APP) $(SIMPLE_APP) $(SALVEINFO_APP) $(ALIASTOOL_APP)
	@echo "test !"
$(EBOX_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/ebox/ebox.c -o $@ -L./ -lsoem -lpthread
$(EEPROMTOOL_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/eepromtool/eepromtool.c -o $@ -L./ -lsoem -lpthread
$(EOE_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/eoe_test/eoe_test.c -o $@ -L./ -lsoem -lpthread
$(FIRM_UPDATE_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/firm_update/firm_update.c -o $@ -L./ -lsoem -lpthread
$(RED_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/red_test/red_test.c -o $@ -L./ -lsoem -lpthread
$(SIMPLE_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/simple_test/simple_test.c -o $@ -L./ -lsoem -lpthread
$(SALVEINFO_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/slaveinfo/slaveinfo.c -o $@ -L./ -lsoem -lpthread
$(ALIASTOOL_APP):
	$(CROSS_COMPILE)$(CC) $(CFLAGS) ./test/linux/aliastool.c -o $@ -L./ -lsoem -lpthread
# 静态库生成规则
$(LIB_NAME): $(SOEM_OBJ)
	$(CROSS_COMPILE)ar rcs $@ $^
# 编译规则：将.c文件编译成.o文件
%.o: %.c
	$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< -o $@
# 清理生成的文件
clean: clean_app clean_test
clean_app:
	rm -f $(SOEM_OBJ) $(LIB_NAME) $(USER_OBJ) $(APP_NAME)
clean_test:
	rm -f $(EBOX_APP) $(EEPROMTOOL_APP) $(EOE_APP) $(FIRM_UPDATE_APP) $(RED_APP) $(SIMPLE_APP) $(SALVEINFO_APP) $(ALIASTOOL_APP)

